<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@page import="java.sql.*"%>
<%@page import="util.Linksql.*"%>
<%@page import="java.sql.Connection.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>公告</title>
    <style type="text/css">
        #annocement {
            width: 500px;
            height: 400px;
            margin-left: 220px;
            margin-top: 110px;
        }

        #annocement .title {
            font-family: "微软雅黑";
            font-size: 24px;
            padding-left: 20px;
        }

        hr {
            width: 500px;
            height: 5px;
            background-color: #006600;
            float: right;
            margin: 15px 0;
        }

        a:link {
            color: #2F0000;
            text-decoration: none;
        }

        a:visited {
            color: #2F0000;
            text-decoration: none;
        }

        a:hover {
            color: #0000FF;
            text-decoration: none;
        }

        a:active {
            color: #0000FF;
            text-decoration: none;
        }
    </style>
</head>
<body>
<div id="annocement">
    <div class="title">通知公告</div>
    <hr />
    <%
        try {
            Class.forName("com.mysql.jdbc.Driver"); // 驱动程序名
            Connection connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/library", "root", "20030607");
            //连接数据库
            System.out.println("数据库连接成功！");
    %>
    <div class="content">
        <%
            String sql = "select * from announcement order by announcement_num desc"; //查询语句
            Statement st = connection.createStatement();
            ResultSet resultSet = st.executeQuery(sql);
            while (resultSet.next()) {
        %>
        <table>
            <th><%=resultSet.getString("announcement_title")%> </a></th>
            <td ><%=resultSet.getString("content")%></td>
            <td ><%=resultSet.getString("time")%></td>
        </table>
        <%
                }
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("数据库连接失败");
            }
        %>
    </div>
</div>
</body>
</html>

